package com.audaque.springboot.foshanupload.web.strategydemo.strategy.factory;

/**
 * @author zgb
 * @desc ...
 * @date 2022-02-18 11:47:03
 */


import com.audaque.springboot.foshanupload.web.strategydemo.strategy.iface.Strategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Service
public class FactoryForStrategy {

    @Autowired
    Map<String, Strategy> strategys = new ConcurrentHashMap<>(3);

    public Strategy getStrategy(String component) throws Exception{
        Strategy strategy = strategys.get(component);
        if(strategy == null) {
            throw new RuntimeException("no strategy defined");
        }
        return strategy;
    }


}
